package com.internetCafes.spms.web.customer.service.impl.customer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.internetCafes.spms.web.customer.entity.customer.CustomerQuali;
import com.internetCafes.spms.web.customer.mapper.customer.CustomerQualiMapper;
import com.internetCafes.spms.web.customer.service.customer.ICustomerQualiService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sms.common.util.hutool.core.collection.CollectionUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 客户资质表 服务实现类
 * </p>
 *
 * @author Zj
 * @since 2021-10-20
 */
@Service
public class CustomerQualiServiceImpl extends ServiceImpl<CustomerQualiMapper, CustomerQuali> implements ICustomerQualiService {

    @Override
    public boolean removeByCustomerIdList(List<Long> customerIdList) {
        return remove(new LambdaQueryWrapper<CustomerQuali>().in(CustomerQuali::getCustomerId, customerIdList));
    }

    @Override
    public boolean config(Long customerId, List<Long> qualiIdList) {
        remove(new LambdaQueryWrapper<CustomerQuali>()
                .eq(CustomerQuali::getCustomerId, customerId));
        if (CollectionUtil.isNotEmpty(qualiIdList)) {
            List<CustomerQuali> qualiBatchDo = qualiIdList
                    .stream()
                    .map(qualiId -> {
                        CustomerQuali customerQuali = new CustomerQuali();
                        customerQuali.setQualiId(qualiId)
                                .setCustomerId(customerId);
                        return customerQuali;
                    }).collect(Collectors.toList());
            return saveBatch(qualiBatchDo);
        }
        return true;
    }
}
